﻿package {
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	
	import com.googlecode.milib.MILibMain;
	import com.googlecode.milib.actionControll.MLActionIniMidEnd;
	import com.googlecode.milib.base.MLActionClass;
	import com.googlecode.milib.display.MCAnimIniMidEnd;
	import com.googlecode.milib.display.service.MLMC;
	import com.googlecode.milib.service.singleton.KeyboardService;
	import com.googlecode.milib.vo.MLEvent;
	import com.googlecode.milib.vo.MLEventInfo;	

	/**
	 * @author Marek Brun 'minim'
	 */
	public class RunningClassesMain extends MovieClip {

		private var mlmcAnim:MLMC;
		private var a:MCAnimIniMidEnd;
		private var b:MCAnimIniMidEnd;
		private var c:MCAnimIniMidEnd;
		private var d:MCAnimIniMidEnd;
		private var e:MCAnimIniMidEnd;
		private var f:MLActionIniMidEnd;
		private var g:MCAnimIniMidEnd;
		private var ks:KeyboardService;
		private var aController:MCActionController;
		private var bController:MCActionController;
		private var cController:MCActionController;
		private var dController:MCActionController;
		private var eController:MCActionController;
		private var fController:MCActionController;
		private var gController:MCActionController;
		
		public function RunningClassesMain() {
			stage.scaleMode=StageScaleMode.NO_SCALE; 
			stage.align=StageAlign.TOP_LEFT;
			MILibMain.init(this);
			
			mlmcAnim=MLMC.forInstance(MovieClip(getChildByName('anim')));
			mlmcAnim.mc.gotoAndStop(1);
			
			a=new MCAnimIniMidEnd(mlmcAnim.mc, 'aIni0', 'aIni1', 'aEnd0', 'aEnd1');
			aController=new MCActionController(mlmcAnim.getMC('a'), a, 'A');
			
			b=new MCAnimIniMidEnd(mlmcAnim.mc, 'bIni0', 'bMid', 'bMid', 'bEnd1', a);
			bController=new MCActionController(mlmcAnim.getMC('b'), b, 'B');
			
			c=new MCAnimIniMidEnd(mlmcAnim.mc, 'cIni0', 'cMid', 'cMid', 'cEnd1', a);
			cController=new MCActionController(mlmcAnim.getMC('c'), c, 'C');
			
			d=new MCAnimIniMidEnd(mlmcAnim.mc, 'dIni0', 'dIni1', 'dEnd0', 'dEnd1', a);
			dController=new MCActionController(mlmcAnim.getMC('d'), d, 'D');
			
			e=new MCAnimIniMidEnd(mlmcAnim.mc, 'eIni0', 'eMid', 'eMid', 'eEnd1', d);
			eController=new MCActionController(mlmcAnim.getMC('e'), e, 'E');
			
			f=new MLActionIniMidEnd(null, null, a);
			fController=new MCActionController(mlmcAnim.getMC('f'), f, 'F');
			
			g=new MCAnimIniMidEnd(mlmcAnim.mc, 'gIni0', 'gMid', 'gMid', 'gEnd1', f);
			gController=new MCActionController(mlmcAnim.getMC('g'), g, 'G');
			
			ks=KeyboardService.getInstance();
			ks.addEventListener(ks.event_Down, onKeyboardDown);
			
		}
		
//********************************************************************************************
//		events for RunningClassesMain
//********************************************************************************************
		private function onKeyboardDown(event:MLEvent):void {
			switch(event.info.data.keyCode){
				case KeyboardService.KEY_A:
					a.setIsRunning(!a.getIsRunningFlag());
				break;
				case KeyboardService.KEY_B:
					b.setIsRunning(!b.getIsRunningFlag());
				break;
				case KeyboardService.KEY_C:
					c.setIsRunning(!c.getIsRunningFlag());
				break;
				case KeyboardService.KEY_D:
					d.setIsRunning(!d.getIsRunningFlag());
				break;
				case KeyboardService.KEY_E:
					e.setIsRunning(!e.getIsRunningFlag());
				break;
				case KeyboardService.KEY_F:
					f.setIsRunning(!f.getIsRunningFlag());
				break;
				case KeyboardService.KEY_G:
					g.setIsRunning(!g.getIsRunningFlag());
				break;
			}
		}
		
	}
}
